export function debounce(fn: Function, delay: number, immediate: boolean = false) {
    let timer: number | null = null;
    return (...args: any) => {
        if (timer) {
            window.clearTimeout(timer)
        }
        if (immediate && !timer) {
            fn.apply(fn, args);
        }
        timer = window.setTimeout(() => {
            fn(...args)
        }, delay)
    }
}